import { AbstractPlatform } from './AbstractPlatform';
import { ProtocolType } from '../core/interfaces';
import { exec } from 'child_process';
import { promises as fs } from 'fs';
import * as path from 'path';

export class WindowsPlatform extends AbstractPlatform {
    async readFile(filePath: string, encoding = 'utf-8'): Promise<string> {
        // Windows路径处理
        const normalizedPath = path.win32.normalize(filePath);
        return fs.readFile(normalizedPath, { encoding: encoding as BufferEncoding });
    }

    async writeFile(filePath: string, content: string): Promise<void> {
        const normalizedPath = path.win32.normalize(filePath);
        return fs.writeFile(normalizedPath, content);
    }

    async execCommand(command: string): Promise<{ stdout: string, stderr: string }> {
        return new Promise((resolve, reject) => {
            exec(command, { shell: 'cmd.exe' }, (error, stdout, stderr) => {
                if (error) {
                    reject(error);
                } else {
                    resolve({ stdout, stderr });
                }
            });
        });
    }

    async httpRequest(url: string, options?: any): Promise<any> {
        // 使用Windows特定的HTTP客户端实现
        throw new Error('Not implemented');
    }

    getPlatformType(): 'windows' | 'linux' | 'macos' | 'unknown' {
        return 'windows';
    }

    supportedProtocols(): ProtocolType[] {
        return [
            ProtocolType.FILE,
            ProtocolType.HTTP,
            ProtocolType.COMMAND
        ];
    }
}